package ead.cs.domain;

import java.util.LinkedHashSet;
import java.util.Set;

public class Permission {

    private Permission(){

    }

    public enum PermissionType {
        CREATE_USER, ADD_SHIP, UPDATE_SCHEDULE, VIEW_REPORT, VIEW_SCHEDULE
    }

    public static Set<String> getPermissionsByRoleType(Role.RoleType roleType) {
        switch (roleType) {
            case ADMIN:
                return getAdminPermissions();
            case MANAGER:
                return getManagerPermissions();
            case STAFF:
                return getStaffPermissions();
            case CUSTOMER:
                return getCustomerPermissions();
            default:
                throw new UnsupportedOperationException();
        }
    }

    private static Set<String> getCustomerPermissions() {
        Set<String> permissionSet = new LinkedHashSet<String>();
        permissionSet.add(PermissionType.VIEW_SCHEDULE.name());
        return permissionSet;
    }

    private static Set<String> getStaffPermissions() {
        Set<String> permissionSet = new LinkedHashSet<String>(getCustomerPermissions());
        //more permissions
        return permissionSet;
    }

    private static Set<String> getManagerPermissions() {
        Set<String> permissionSet = new LinkedHashSet<String>();
        permissionSet.addAll(getCustomerPermissions());
        permissionSet.addAll(getStaffPermissions());
        permissionSet.add(PermissionType.VIEW_REPORT.name());
        permissionSet.add(PermissionType.ADD_SHIP.name());
        permissionSet.add(PermissionType.UPDATE_SCHEDULE.name());
        return permissionSet;
    }

    private static Set<String> getAdminPermissions() {
        Set<String> permissionSet = new LinkedHashSet<String>();
        permissionSet.addAll(getCustomerPermissions());
        permissionSet.addAll(getStaffPermissions());
        permissionSet.addAll(getManagerPermissions());
        permissionSet.add(PermissionType.CREATE_USER.name());
        return permissionSet;
    }


}
